"use strict"

import {Native} from './native.js'
import {Task} from './task.js'

/**
 * 选择图片/视频
 * @static
 * @author GuoHua Liu
 * @copyright Copyright © 2019 GuoHua Liu. All rights reserved.
 */
class pick {


    /**
     * 从图库选择图片
     * @property {Object}
     * @returns {Task}
     */
    static images(option) {

        if (!option) {
            option = {count:1}
        } else {
            if (!option.count) {
                option.count = 1
            }
        }

        let newTask = new Task()
        if(!Native.getInstance().isHos()) {
            newTask.__reject({"errMsg":"当前环境不支持", "errCode":-1})
            return newTask
        }

        let task = Native.getInstance().callNative("pick", {
            "method":"images",
            "count":option.count
        }, true, resp=>{
            newTask.__resolve(resp);
        }, (error)=>{newTask.__reject(error)})

        newTask.__setAbort(task.abort)
        return newTask
    }


    /**
     * 屏幕截图
     * @property {Object}
     * @returns {Task}
     */
    static screenshot() {
        let newTask = new Task()
        if(!Native.getInstance().isHos()) {
            newTask.__reject({"errMsg":"当前环境不支持", "errCode":-1})
            return newTask
        }

        let task = Native.getInstance().callNative("pick", {
            "method":"screenshot"
        }, true, resp=>{
            newTask.__resolve(resp);
        }, (error)=>{newTask.__reject(error)})

        newTask.__setAbort(task.abort);
        return newTask
    }
}

export {pick}
